#define _CRT_SECURE_NO_WARNINGS 1

#include <iostream>
using namespace std;

class Solution {
public:
    int longestSemiRepetitiveSubstring(string s) {
        int i = 0;
        int j = 0;
        int flag = 0;
        int id = 0;
        int sz = s.size();
        int ans = 0;
        for (j = 1; j < sz; j ++) {
            if (s[j] == s[j - 1]) {
                if (flag == 0) {
                    flag = 1;
                    id = j;
                }
                else {
                    ans = max(ans, j - i);
                    i = id;
                }
            }
        }
        ans = max(ans, j - i);
        return ans;
    }
};